package com.songqintuan.common.dal.ibatis.basedao;

import java.io.Serializable;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.songqintuan.common.bean.Page;
import com.songqintuan.common.dal.ibatis.dao.IBatisEntityDao;

public class IbatisDao<T, PK extends Serializable> implements IIbatisDao<T, PK> {

	protected Class<T> entityClass;// DAO所管理的Entity类型.
	protected String primaryKeyName;// DAO所管理的PK类型.
	protected Class<PK> pkClass;
	private IBatisEntityDao<T, PK> ibatisDao;
	
	public void setEntityClass(Class<T> entityClass) {
		ibatisDao.setEntityClass(entityClass);
		this.entityClass = entityClass;

	}
	
	public Class<T> getEntityClass(){
		return this.entityClass;
	}
	public void setPrimaryKeyName(String primaryKeyName) {  
		ibatisDao.setPrimaryKeyName(primaryKeyName);  
		this.primaryKeyName = primaryKeyName;
		}
	
	public void setPKClass(Class<PK> pkClass) {
		ibatisDao.setPKClass(pkClass);
		this.pkClass = pkClass;

	}
	
	public IBatisEntityDao<T, PK> getIbatisDao() {
		return ibatisDao;
	}

	public void setIbatisDao(IBatisEntityDao<T, PK> ibatisDao) {
		this.ibatisDao = ibatisDao;
	}

	public IbatisDao(){
	}
	public Integer count(String propertyName, Object propertyValue) throws SQLException, Exception {
		// TODO Auto-generated method stub
		return ibatisDao.count(propertyName, propertyValue);
	}
	public Integer countLikeByMap(String[] propertyNames,
			Object[] propertyValues) throws Exception, Exception {
		// TODO Auto-generated method stub
		return ibatisDao.countLikeByMap(propertyNames, propertyValues);
	}
	public int delete(T o) throws SQLException {
		// TODO Auto-generated method stub
		return ibatisDao.delete(o);
	}
	public int deleteById(PK id) throws SQLException {
		// TODO Auto-generated method stub
		return ibatisDao.deleteById(id);
	}
	public void deleteByIdsMap(List<PK> ids, String[] properties,
			Object[] propertyValues) throws Exception {
		// TODO Auto-generated method stub
		ibatisDao.deleteByIdsMap(ids, properties, propertyValues);
	}
	public int deleteByMap(String[] properties, Object[] propertyValues) throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.deleteByMap(properties, propertyValues);
	}
	public List<T> find(Map<String, Object> map) throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.find(map);
	}
	public List<T> findBy(String property, Object value) throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.findBy(property, value);
	}
	public T findById(PK id) throws Exception, Exception {
		// TODO Auto-generated method stub
		return ibatisDao.findById(getEntityClass(), id);
	}
	public List<T> findByIds(List<PK> ids) throws Exception, Exception {
		// TODO Auto-generated method stub
		return ibatisDao.findByIds(getEntityClass(), ids);
	}
	public List<T> findByLike(String name, String value) throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.findByLike(name, value);
	}
	public T findUniqueBy(String name, Object value) {
		// TODO Auto-generated method stub
		return ibatisDao.findUniqueBy(name, value);
	}
	public T findUniqueByMap(Map<String, Object> map) throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.findUniqueByMap(map);
	}
	public List<T> getAll() throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.getAll();
	}
	public void insert(T o) throws Exception {
		// TODO Auto-generated method stub
		ibatisDao.insert(o);
	}
	public Page<T, PK> pagedQuery(String sqlName,
			HashMap<String, Object> hashMap, Integer pageNo, Integer pageSize) throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.pagedQuery(sqlName, hashMap, pageNo, pageSize);
	}
	public Page<T, PK> pagedQuery(String sqlName, String[] properties,
			Object[] propertyValues, Integer pageNo, Integer pageSize) throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.pagedQuery(sqlName, properties, propertyValues, pageNo, pageSize);
	}
	public int update(T o) throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.update(o);
	}
	public int update(PK id, String[] properties, Object[] propertyValues) throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.update(id, properties, propertyValues);
	}
	public int updateByIdsMap(List<PK> ids, String[] properties,
			Object[] propertyValues) throws Exception {
		// TODO Auto-generated method stub
		return ibatisDao.updateByIdsMap(ids, properties, propertyValues);
	}
}
